<?php
include('/var/www/html/new/d/module/api/function.class.php');
$ac='16ucom';
$pw='c33367701511b4f6020ec61ded352059';
$inSide= new SoapClient(null,array("location" => "http://localhost/open/openService/pft_insideMX.php","uri" => "www.16u.com?ac_16u=$ac|pw_16u=$pw|auth_16u=true"));

$PFT_infunction = new AllFunction();

if (!class_exists("go_sql")){
	include("/var/www/html/new/conf/le.je");
	$le=new go_sql();
	$le->connect();
}

$order = $_REQUEST['order_id'];
// $order = 'pft144228863813154835';
$selorder = "select pftOrder from all_api_order where coopB=2 and oStatus= 0 and tempOrder='$order' limit 1";
$GLOBALS['le']->query($selorder);
$GLOBALS['le']->fetch_assoc();
$pftOrder = $GLOBALS['le']->f('pftOrder');

$pft_order_xml = $PFT_infunction->Select_PFTorder($pftOrder);

$UUtnum = (string)$pft_order_xml->Rec->UUtnum;
$UUtotalmoney =(int)$pft_order_xml->Rec->UUtotalmoney/100; //总价
$UUaids=(string)$pft_order_xml->Rec->UUaids;
if($UUaids == 0){  //供应商
	$UUaid = (string)$pft_order_xml->Rec->UUaid;
}else{
	$UUaidss= explode(',',$UUaids);
	$UUaid = $UUaidss[0];
}
$UUpaystatus = (int)$pft_order_xml->Rec->UUpaystatus; //支付状态
$UUstatus = (int)$pft_order_xml->Rec->UUstatus; //订单状态

if($UUaid == 4274 && $UUstatus == 0 && $UUpaystatus == 1){
	$response = array(
		'is_success'	=> "true",
		'pay_amount' 	=> $UUtotalmoney,
		'pay_currency'	=> 'CNY',
		'remark'		=> '支付成功',
		'err_code'		=> 0 ,
		'err_msg'		=> '支付成功'
		
	);
}
else{
	$response = array(
		'is_success'	=> "false",
		'pay_amount' 	=> '0.00',
		'pay_currency'	=> 'CNY',
		'remark'		=> '没有支付',
		'err_code'		=> -1,
		'err_msg'		=> '订单不属于携程分销订单或者订单状态出错'
		
	);
}

$response_json  = json_encode($response);
echo $response_json;

logfile(json_encode($_REQUEST).'|'.$response_json,'ctrip_pay_Confirm');

// function logfile($txt,$logname){
	// $fp = fopen('/var/www/html/new/d/logs/api/ctrip/'.$logname.date('Y-m-d').'.txt',"a");
	// flock($fp, LOCK_EX) ;
	// fwrite($fp,date('Y-m-d H:i:s').'|'.$txt."\n");
	// flock($fp, LOCK_UN);
	// fclose($fp); 
// }
function logfile($word,$path){
	$filepath= '/var/www/html/new/d/logs/api/ctrip/'.$path.'.txt';
	if(file_exists($filepath)){
		$word = date("Y-m-d H:i:s")."|".$word;
		$word = mb_convert_encoding($word, 'GBK', 'UTF-8');
		$maxsize  = 1024*1024*10;
		$filesize = filesize($filepath);
		$filetype = end(explode(".",$filepath));
		$filename = substr($filepath,0,strpos($filepath,'.'));
		if($filesize>$maxsize)
		{
			rename($filepath, $filename.'_'.date('YmdHis').'.'.$filetype);
			$handler=fopen($filepath,'w');
			flock($handler, LOCK_EX) ;
			fwrite($handler,"\n".$word);
			flock($handler, LOCK_UN);
			fclose($handler);
		}
		else
		{
			$fp = fopen('/var/www/html/new/d/logs/api/ctrip/'.$path.'.txt',"a");
			flock($fp, LOCK_EX);
			fwrite($fp,$word."\n");
			flock($fp, LOCK_UN);
			fclose($fp);
		}
	}else{
		$fp = fopen('/var/www/html/new/d/logs/api/ctrip/'.$path.'.txt',"a");
		flock($fp, LOCK_EX);
		fwrite($fp,date('Y-m-d H:i:s')."|".$word."\n");
		flock($fp, LOCK_UN);
		fclose($fp);
	}
}

?>